<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>登录</title>
  <script src="./jquery-3.0.0.min.js"></script>
  <script src="./confing.js"></script>

</head>

<body>
  <form id="formName">
    手机号<input type="number" name="phone"></br>
    密码<input type="password" name="password"></br>
    用户昵称<input type="text" name="username"></br>

  </form>
  <button id="submit">注册</button>
  <button onClick="goLogin()">去登录</button>
  <script>
    function goList() {
      window.location.href = "./index.html";
    }
    function goLogin() {
      window.location.href = "./login.html";
    }
    $(function () {
      console.log('页面初始化')

      $('#submit').bind('click', () => {
        let value = $('#formName').serializeArray();
        let data = {};
        $.each(value, function (index, item) {
          data[item.name] = item.value;
        });;
        $.ajax({
          url: DBHOST + "/user/register",
          type: "POST",
          data: data,
          success: function (result) {
            console.log(result);
            const { code, data } = result;
            if (code == 200) {
              alert('注册成功')
            } else {
              alert(data)
            }
          },
          error: function (err) {
            let { code, msg } = err.responseJSON;
            alert(msg);
          }
        });
      })
    })

  </script>
</body>

</html>